//
//  ImageCollectionViewCell.m
//  MedicineBox
//
//  Created by dllo on 15/9/30.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ImageCollectionViewCell.h"
#import "ConsultTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "ConsultModel.h"
#import "MJRefresh.h"
// 自适应宽度比例
#define OffWidth [UIScreen mainScreen].bounds.size.width / 375
// 自适应高度比例
#define OffHeight [UIScreen mainScreen].bounds.size.height / 667

@interface ImageCollectionViewCell () <UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate>

@property (nonatomic, retain) NSString *imageV;
@property (nonatomic, retain) NSString *text;
@end
@implementation ImageCollectionViewCell
- (void)dealloc
{
    [super dealloc];
}

- (instancetype) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createCustomCell];
        self.tableArr = [NSMutableArray array];
        [self downFresh];
        [self upAdd];
    }
    return self;
}

// 下拉刷新
- (void)downFresh
{
    
    self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self.delegate sendCollectionViewCell:self];
    }];
    
}
// 上拉加载
- (void)upAdd{
    
    self.tableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self.delegate sendCollectionIndex:(long)_index1.item];
        [self.tableView.footer endRefreshing];
    }];
    
}


- (void)createCustomCell
{
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - 143) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor whiteColor];
    [_tableView registerClass:[ConsultTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.contentView addSubview:_tableView];
    


}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _tableArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70 * OffHeight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ConsultModel *model = [_tableArr objectAtIndex:indexPath.row];
    ConsultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    NSString *str = model.v_title;
    str = [str stringByReplacingOccurrencesOfString:@"贝多" withString:@"医药管家"];
    cell.label.text = str;
    NSString *strImage = [NSString stringWithFormat:@"http://static.beiduo.cc/%@",model.v_main_pic];
    [cell.imageV sd_setImageWithURL:[NSURL URLWithString:strImage] placeholderImage:nil];
    cell.selectionStyle = UITableViewScrollPositionNone;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ConsultModel *model = [_tableArr objectAtIndex:indexPath.row];
    [self.delegate sendWebText:model.v_content];
}

- (void)setIndex1:(NSIndexPath *)index
{
    if (_index1 != index) {
        _index1 = index;
//        NSLog(@"111111111========%ld",(long)_index1.item );

//        [self.delegate sendCollectionIndex:(long)self.index.item];
    }
//    NSLog(@"22222222========%ld",(long)_index1.item );

}

@end
